package com.project.biz.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.framework.core.result.BasePage;
import com.project.biz.CmsBannerBiz;
import com.project.common.utils.IpageToPage;
import com.project.entity.CmsBanner;
import com.project.mapper.CmsBannerMapper;
import com.project.pojo.dto.CmsCapitalFlowDTO;
import com.project.pojo.model.GetCmsCapitalFlowModel;
import com.project.pojo.model.QueryBannerModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @description: banner管理 业务层接口实现类
 * @author: longer
 * @create: 2020-12-18 17:52
 **/
@Slf4j
@Service
public class CmsBannerBizImpl extends ServiceImpl<CmsBannerMapper, CmsBanner> implements CmsBannerBiz {

    /**
     * 按条件查询banner
     * @param queryBannerModel
     * @return
     */
    public BasePage<CmsBanner> getBannerList(QueryBannerModel queryBannerModel){

        Page<CmsBanner> page = new Page<>(queryBannerModel.getPageNo(), queryBannerModel.getPageSize());
        IPage<CmsBanner> iPage = this.baseMapper.getBannerList(page, queryBannerModel);
        BasePage<CmsBanner> basePage = IpageToPage.toBasePage(iPage, CmsBanner.class);

        return basePage;
    }

    /**
     * 增加banner
     * @param banner
     * @return
     */
    @Transactional(rollbackFor = Exception.class , isolation = Isolation.REPEATABLE_READ, timeout = 30)
    @Override
    public Integer addBanner(CmsBanner banner) {
        return this.baseMapper.insert(banner);
    }

    /**
     * 删除banner
     * @param bannerId
     * @return
     */
    @Transactional(rollbackFor = Exception.class , isolation = Isolation.REPEATABLE_READ, timeout = 30)
    @Override
    public Integer deleteBanner(Long bannerId) {
        return this.baseMapper.deleteById(bannerId);
    }

    /**
     * 修改banner
     * @param banner
     * @return
     */
    @Transactional(rollbackFor = Exception.class , isolation = Isolation.REPEATABLE_READ, timeout = 30)
    @Override
    public Integer updateBanner(CmsBanner banner) {

        return this.baseMapper.updateById(banner);
    }


}
